package day07;

import java.awt.font.FontRenderContext;

/** 验证码 */
public class VerificationCode {
    public static void main(String[] args) {
        String code = generateVeriCode(6);//验证码长度
        System.out.println("验证码:"+code);
    }
    /** 生成验证码 */      //生成验证码
    public static String generateVeriCode(int len){
              //密码
        String code = "";
        char[] chs = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w',
                      'x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T',
                      'U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9'
        };
        for(int i = 1;i<=len;i++){
            //随机char[]下标数字(62-1)        //*数组元素长度(62)                      //0--62之间整数
            int index = (int)(Math.random()*chs.length);//int index = rand.nextInt(chs.length);//Random rand = new Random
            code += chs[index];////int index = 0;chs[index=0(a)]对应char[] chs字符组下标0/** String code = "a" */
        }
        return code;
    }
}
